<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false"%>
<%@ include file="../common/taglibs.jsp"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${rootPath}/css/a.css" type="text/css" rel="stylesheet" />
<link href="${rootPath}/css/index.css" type="text/css" rel="stylesheet" />
<link href="${rootPath}/css/common.css" type="text/css" rel="stylesheet" />
<title>终端激活统计</title>

<script type="text/javascript"
	src="<s:url value="/js/jquery-1.3.2.js" />"></script>
<script type="text/javascript" src="<s:url value="/js/common.js" />"></script>
<script language="javascript" type="text/javascript"
	src="<s:url value="/js/My97DatePicker/WdatePicker.js"/>"></script>
<script type='text/javascript' src='<s:url value="/dwr/engine.js"/>'></script>
<script type='text/javascript' src='<s:url value="/dwr/interface/MccQuery.js"/>'></script>
<script type="text/javascript">
$(document).ready(function(){
	loadAgent();
	$("#agentId").change(function(){
		loadAgent();
	});
	
      $("#sub").click(function(){
         if(!checkDate()){
           return false;
         }
         $("#importForm").attr("action","<%=basePath%>/termStatistics/queryTermStatisticsList.ct");
		 $("#importForm").submit();
       
      });
      
      $("#szPower").click(function() {
		 $("#importForm").attr("action","<%=basePath%>/termStatistics/excelTermStatisticsList.ct");
		 $("#importForm").submit();
	   });				
      
   });

	function   str2date(str){
		var d=null;   
		var reg=/^(\d{4})(\d{2})(\d{2})$/  ;
			if(arr=str.match(reg))d=new   Date(Number(arr[1]),Number(arr[2])-1,Number(arr[3])) ; 
		return   d;   
	}  

	function  checkDate(){
		var endTime = $("#maxDate").val();
		var beginTime = $("#minDate").val();
		
		if(!endTime || !beginTime){
			alert("起始时间范围必须选择!");
			return false;
		} 
		var date1=str2date(beginTime);
		var date2=str2date(endTime);
			
		if(date1.getMonth()!=date2.getMonth()){
		    alert("选择的起始时间不在同一个月内！");
			return false;
		}
		if(date2.getDate()-date1.getDate()>6){
			alert("选择的起始~结束时间跨度不能大于7天！");
			return false;
		}
		if(date2.getDate()<date1.getDate()){
			alert("选择的结束时间不能小于起始时间！");
			return false;
		}
		return true;
	}
	
	function loadAgent()
	{
		$("#directId").empty();
		$("#directId").append("<option value=''>不限</option>");
		var directId="${searchCondition.directId}";
		var id=$("#agentId").val();
		if(id.trim().length<=0)
		{
			return;
		}
		$.ajax({
		 	url:'<s:url value="/termStatistics/directAgent.ct"/>',
		 	data:'super_id='+id,
	  		dataType:"json",
	  		type:"POST",
	  		success:function(data){
	  			for (var i=0;i<data.length;i++) {
	  					var str="";
		  				if(data[i].id==directId)
		  				{
		  					str=str+"selected='selected'"
		  				}
		  				$("#directId").append("<option "+str+" value='"+data[i].id+"'>"+ data[i].name+ "</option>");	  				
	  			 }
	  		},error:function(rsg){
	  			alert("加载直属代理商，请联系客服~！");
	  		}	
	 	});  
	}
</script>
</head>
<body>
<table class="tb">
    <tbody>
		<s:form id="importForm" action="queryTermStatisticsList.ct" method="post"
			namespace="/termStatistics"  theme="simple">
			<s:hidden name="currentAgentFlag" value="%{currentAgentFlag}"/>
	        <tr class="tb-line">
	            <td class="tb-td" colspan="6"><div class="tb-h2">POS收单运营管理平台</div></td>
	        </tr>
	
	        <tr class="tb-line">
	            <td class="tb-td" colspan="6"><div class="tb-h3">终端已激活统计</div></td>
	        </tr>
			<tr class="tb-line">
			    <td width="12%" style="min-width: 150px" align="right" class="tb-td">
			    	<div class="tb-h4">
			    	<s:if test="currentAgentFlag=='exist'">代理商</s:if>
			    	<s:else>所属分公司：</s:else>
			    	</div>
			    </td>
				<td class="tb-td">
                	<label class="tb-select">
                	<s:if test="agentFlag=='exist'">
                		<s:select cssClass="queryWidth" name="searchCondition.agentId" id="agentId"
							list="#request.opList" listKey="id" listValue="realName"/>							
                	</s:if>
					<s:else>
						<s:select cssClass="queryWidth" name="searchCondition.agentId" id="agentId"
							list="#request.opList" listKey="id" listValue="realName"  headerKey="" headerValue="不限" />
					</s:else>
                	</label>                	
				</td>
	            <td width="12%" style="min-width: 150px" align="right" class="tb-td">
	                <div class="tb-h4">SN序列号：</div></td>
	            <td class="tb-td">
	            	<label class="tb-input-normal">
	               		<s:textfield name="searchCondition.serialNum"/>
	               		</label>
				</td>		
			</tr>
			<tr class="tb-line">
			    <td width="12%" style="min-width: 150px" align="right" class="tb-td">
			    	<div class="tb-h4">
			    	<s:if test="currentAgentFlag=='exist'">直属子代理</s:if>
			    	<s:else>直属代理商：</s:else>
			    	</div>
			    </td>
				<td class="tb-td">
                	<label class="tb-select">
						<s:select cssClass="queryWidth" name="searchCondition.directId" id="directId"
							list="#{'':'不限' }" />
                	</label>                	
				</td>
	            <td width="12%" style="min-width: 150px" align="right" class="tb-td">
	                <div class="tb-h4">激活日期：</div></td>
	            <td class="tb-td">
	                <label class="tb-input-mini">
	                	<s:textfield id="minDate" name="searchCondition.minDate" onFocus="WdatePicker({dateFmt:'yyyyMMdd',readOnly:true,wdate:true,errDealMode:0});"
							theme="simple" cssClass="queryWidth" /> 
					</label>至：
					<label class="tb-input-mini">
						<s:textfield id="maxDate" name="searchCondition.maxDate" onFocus="WdatePicker({dateFmt:'yyyyMMdd',readOnly:true,wdate:true,errDealMode:0});"
							theme="simple" cssClass="queryWidth" />
					</label>
					<code class="asterisk">*</code>
				</td>		
			</tr>
				<tr>
					<td colspan="6">&nbsp;</td>
				</tr>
				<tr>
					<td colspan="6" align="center"><div style="color: blue;">
							<s:actionmessage />
						</div>
						<div style="color: red;">
							<s:actionerror />
						</div>
					</td>
				</tr>

				<tr class="tb-line">
					<td class="tb-td line-submit" align="right" colspan="6">
                		<label class="tb-input-submit">
					 		<s:submit value="查询" id="sub" /> 
		                </label>
		                <label class="tb-input-submit">
				             <s:reset value="取  消" />
		                </label>
						   <s:if test="#request.searchRsList != null && #request.searchRsList.size>0">
								
				                <label class="tb-input-submit">
									<input id="szPower" type="submit" value="导出Excel" />
				                </label>
					       </s:if>
						   <s:else>
						   
			                <label class="tb-input-submit">
								<input id="szPower" disabled="disabled" value="导出Excel" type="submit" />
			                </label>
					       </s:else>
							</td>
				</tr>
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
				<s:if
					test="#request.searchRsList != null && #request.searchRsList.size>0">
					<tr class="tb-line">
						<td class="tb-td paging" colspan="12" align="left">&nbsp;&nbsp;&nbsp;&nbsp; <page:pageCount
								max_pages="11" totalPage="${requestScope.totalPage}"
								currentPage="${requestScope.currentPage}"
								action="${rootPath}/termStatistics/queryTermStatisticsList.ct?currentPage=" />

						</td>
					</tr>
				</s:if>
			</table> 
		</s:form>
    </tbody>
</table>
<div class="big-tb">
    <table class="tb" style="width: 100%;">
				<thead>
		            <tr class="tb-line">
		                <th class="tb-th" colspan="13">终端已激活信息列表</th>
		            </tr>
					<tr class="tb-line bg-gray">
					    <th class="tb-th"><s:if test="currentAgentFlag=='exist'">代理商</s:if>
			    	<s:else>所属分公司</s:else></th>
						<th class="tb-th"><s:if test="currentAgentFlag=='exist'">直属子代理</s:if>
			    	<s:else>直属代理商</s:else></th>
						<th class="tb-th">商户号</th>
						<th class="tb-th">终端号</th>
						<th class="tb-th">SN序列号</th>
					</tr>
				</thead>
				<tbody>
					<s:iterator value="terminalList" status="stat" id="term">
						<tr class="tb-line">
							<td class="tb-td" align="center">
							 <s:property value="#term.orgName"/>
							</td>
							<td class="tb-td" align="center">
							 <s:property value="#term.agentName"/>
							</td>
							<td class="tb-td" align="center">
							 <s:property value="#term.mid"/>
							</td>
							<td class="tb-td" align="center">
							 <s:property value="#term.tid"/>
							</td>
							<td class="tb-td" align="center">
							 <s:property value="#term.serialNum"/>
							</td>
						</tr>
						</s:iterator>
				</tbody>
    </table>
</div>
</body>
</html>